package com.ruoyi.report.forms.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.report.forms.domain.CtUser;
import com.ruoyi.report.forms.service.ICtUserService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 用户管理Controller
 * 
 * @author taoyunli
 * @date 2024-05-14
 */
@RestController
@RequestMapping("/user")
public class CtUserController extends BaseController
{
    @Autowired
    private ICtUserService ctUserService;

    /**
     * 查询用户管理列表
     */
    @RequiresPermissions("system:user:list")
    @GetMapping("/list")
    public TableDataInfo list(CtUser ctUser)
    {
        startPage();
        List<CtUser> list = ctUserService.selectCtUserList(ctUser);
        return getDataTable(list);
    }

    /**
     * 导出用户管理列表
     */
    //@RequiresPermissions("system:user:export")
    @Log(title = "用户管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CtUser ctUser) throws IOException
    {
        List<CtUser> list = ctUserService.selectCtUserList(ctUser);
        ExcelUtil<CtUser> util = new ExcelUtil<CtUser>(CtUser.class);
        util.exportExcel(response, list, "用户管理数据");
    }

    /**
     * 获取用户管理详细信息
     */
    @RequiresPermissions("system:user:query")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") String userId)
    {
        return AjaxResult.success(ctUserService.selectCtUserByUserId(userId));
    }

    /**
     * 新增用户管理
     */
    @RequiresPermissions("system:user:add")
    @Log(title = "用户管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CtUser ctUser)
    {
        return toAjax(ctUserService.insertCtUser(ctUser));
    }

    /**
     * 修改用户管理
     */
    @RequiresPermissions("system:user:edit")
    @Log(title = "用户管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CtUser ctUser)
    {
        return toAjax(ctUserService.updateCtUser(ctUser));
    }

    /**
     * 删除用户管理
     */
    @RequiresPermissions("system:user:remove")
    @Log(title = "用户管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable String[] userIds)
    {
        return toAjax(ctUserService.deleteCtUserByUserIds(userIds));
    }
}
